@echo off
setlocal enabledelayedexpansion

set buildType=%~1
set buildTarget=%~2
set cangjieFolder=cangjie-!buildTarget!

if /i !buildTarget!==android (
    set cangjieTarget=aarch64-linux-android31
    set cangjieFeatures=feature.env.android
    set ANDROID_CJ_FRONTEND=!CJMP_SDK_HOME!\cjmp-ui\android
    set ANDROID_NDK_DIR=!ANDROID_SDK_ROOT!\ndk\26.3.11579264
    set SYSTEM_STRING=windows-x86_64
    set ANDROID_CANGJIE_PATH=!CJMP_SDK_HOME!\cjmp-tools\third_party\cangjie-android
) else if /i !buildTarget!==ohos (
    set cangjieTarget=aarch64-linux-ohos
    set cangjieFeatures=feature.env.ohos
)

if /i !buildType!==debug (
    set cangjieExtraArgs=-g
) else (
    set cangjieExtraArgs=
)

call !CJMP_SDK_HOME!\cjmp-tools\third_party\%cangjieFolder%\envsetup.bat || exit /b !errorlevel!
cjpm build --no-feature-deduce --enable-features=!cangjieFeatures! --target=!cangjieTarget! !cangjieExtraArgs! || exit /b !errorlevel!
if not exist "..\android\pkgnative_windows\libs\arm64-v8a" (
    mkdir "..\android\pkgnative_windows\libs\arm64-v8a" || exit /b !errorlevel!
)
copy "..\package\target\!cangjieTarget!\!buildType!\pkgnative_windows\libpkgnative_windows.so" "..\android\pkgnative_windows\libs\arm64-v8a" || exit /b !errorlevel!
